This example demonstrates how to combine multiple chart types in a single chart context, dynamically display annotations based on user interaction, and customize appearance and interactivity using chart overlays.
The example uses the following components together:
LineChart: Plots discrete points and connects them with curved lines.AreaChart: Fills the area under a line graph, visually indicating magnitude.RuleLineForLabelChart: Draws a reference line at the selected label and overlays a custom annotation.chartXSelection: Enables user interaction by tracking X-axis selection.The dataset used represents yearly sales performance:
Each entry includes:
sales: Numeric value to be plottedyear: Used as the label on the X-axisgrowth: Additional metric (not directly visualized here)year).setChartSelection callback to update the selected year."catmullRom" for smooth curves between points.sales value in a styled background.ZStack and RoundedRectangle to build a custom annotation view.year) is selected and passed to chartSelection.selectedItem is computed using useMemo.Sales: 2500).This example demonstrates how to:
LineChart, AreaChart, RuleLineForLabelChart) within a single <Chart> container.chartXSelection to enable touch-based exploration.This pattern is ideal for dashboards and interactive reports where data insight and responsiveness are key.